#include <stdio.h>
int main()
{
	int n,num,num2=0,num3=2,num4=0;
	scanf("%d",&n);
	num=n;
	while(num!=0)
	{
		num2++;
		num/=10;
	}
	while(--num2)
	{
		num=num*10+3;
		num3=num3*10+3;
		num4+=num3;
	}
	num4+=3;
	num=num*10+3;
	num--;
	if(n>num)
		printf("%d",num4);
	else
		printf("%d",num4-(num-n)-1);
	return 0;
}